package com.jboy.entity;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

@AllArgsConstructor
@NoArgsConstructor
@Data
public class Student {

    private String name;
    private Integer age;

    /**
     * 集合和JSON相互转化
     */

    public static void  main(String args[]) throws Exception{

            ObjectMapper mapper = new ObjectMapper();
            Map<String, Object> map = new HashMap<>();
            map.put("name", "zs");
            map.put("age","12");
            String param = mapper.writeValueAsString(map);
            System.out.println("===map转json==="+param);
//===map转json==={"name":"zs","age":"12"}

        Map<String, Object> resultMap = mapper.readValue(param, Map.class);
            System.out.println("===json转map==="+resultMap);
//===json转map==={name=zs, age=12}


    }



}
